package net.risesoft.y9public.manager.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;

import net.risesoft.y9.Y9Context;
import net.risesoft.y9.pubsub.event.Y9EntityDeletedEvent;
import net.risesoft.y9public.entity.tenant.Y9TenantApp;
import net.risesoft.y9public.manager.Y9TenantAppManager;
import net.risesoft.y9public.repository.tenant.Y9TenantAppRepository;

/**
 * 租户应用 Manager 实现类
 *
 * @author shidaobang
 * @date 2023/06/14
 * @since 9.6.2
 */
@Service
@Transactional(value = "rsPublicTransactionManager", readOnly = true)
@RequiredArgsConstructor
public class Y9TenantAppManagerImpl implements Y9TenantAppManager {
    
    private final Y9TenantAppRepository y9TenantAppRepository;

    @Override
    @Transactional(readOnly = false)
    public void deleteByAppId(String appId) {
        List<Y9TenantApp> y9TenantAppList = y9TenantAppRepository.findByAppId(appId);
        for (Y9TenantApp ta : y9TenantAppList) {

            Y9Context.publishEvent(new Y9EntityDeletedEvent<>(ta));

            y9TenantAppRepository.delete(ta);
        }
    }
    
}
